/*
 * File Name: Tool.java
 * Release:  1.0
 * Copyrights (c) 2006 lingtong.
 * 
 * �޸���   : lhxiong
 * �޸�ʱ�� : 2006-2-13
 * �޸ļ�¼ :
 */
package com.wsj.util.tool;

/**
 * @author admin
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * ϵͳ�Ĺ������ͣ������ʱ��Ĳ���������ת��
 * 
 * @author qlnie
 * @version 1.0
 * @since 2005-11-8
 */
public class Tool {    
    
    
    /**
     * �Ѽ���ת��������
     * 
     * @param p_l Ҫת���ļ���
     * @return ����
     */
    public static String[] toArray(List p_l) {
        String[] result = new String[p_l.size()];
        for (int i = 0; i < p_l.size(); i++) {
            result[i] = p_l.get(i).toString();
        }
        return result;
    }

    
    /*****
     * 去掉多个空格并将头尾空格挤掉
     * 输入一个处理的字符串,输出将多个空格变成一个空格,并将头尾空格去掉的字符串
     */
    public static String cutMultiSpace(String inputStr)
    {
    	String patternStr ="\\s+"; //\s+匹配一个空格以上
		 Pattern pattern = Pattern.compile(patternStr);
	     Matcher matcher = pattern.matcher(inputStr);
	     String s=matcher.replaceAll(" "); //将多个空格替换成一个空格
	     if(s!=null)
	     {
	    	 return s.trim();
	     }
	     else
	     {
	    	 return "";
	     }
    }
    
    
    /******
     * 去掉多行空格,和<p> </p> 的字符
     */
    public static String dealWithText(String text)
    {
    	String newStr = cutMultiSpace(text);
    	newStr = newStr.replaceAll("<p>", " ");
    	newStr = newStr.replaceAll("</p>", " ");
    	return newStr;
    }
}
